<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="功能房名" prop="roomName">
        <el-input v-model="queryParams.roomName" placeholder="请输入功能房名" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="开放状态" prop="roomStatus">
        <el-select v-model="queryParams.roomStatus" placeholder="请选择开放状态" clearable @change="handleQuery">
          <el-option v-for="dict in dict.type.rt_fu_room_status" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['staff:room:add']">新增功能房</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['staff:room:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['staff:room:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['staff:room:export']">导出</el-button>
      </el-col> -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="roomList" @selection-change="handleSelectionChange"
      :default-sort="{ prop: 'roomCreatetime', order: 'descending' }">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="功能房名" align="center" prop="roomName" />
      <el-table-column label="容纳人数" align="center" prop="roomCapacity" />
      <el-table-column label="使用事项" align="center" prop="roomMatter">
        <template slot-scope="scope">
          <el-tooltip class="item" effect="dark" :content="scope.row.roomMatter || '未填写使用事项'" placement="top">
            <div class="ellipsis">
              {{ scope.row.roomMatter || '未填写使用事项' }}
            </div>
          </el-tooltip>
        </template>
      </el-table-column>
      <!-- <el-table-column label="功能房介绍" align="center" prop="roomInfo" />
      <el-table-column label="功能房用途" align="center" prop="roomPurp" /> -->
      <el-table-column label="开放状态" align="center" prop="roomStatus">
        <template slot-scope="scope">
          <!-- <dict-tag :options="dict.type.rt_fu_room_status" :value="scope.row.roomStatus" /> -->
          <el-switch v-model="scope.row.roomStatus" class="main-el-switch" active-text="开启" inactive-text="关闭"
            active-value="1" inactive-value="0" @change="changeRoomStatus(scope.row)"></el-switch>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="roomCreatetime" width="180" sortable>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.roomCreatetime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="更新时间" align="center" prop="roomUptime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.roomUptime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="功能房图片" align="center" prop="roomImgs" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.roomImgs" :width="50" :height="50" />
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="350">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['staff:room:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['staff:room:remove']">删除</el-button>
          <el-button size="mini" type="text" icon="el-icon-search" v-if="scope.row.roomStatus == 1"
            @click="usageSituation(scope.row)">查看使用情况</el-button>
          <el-button size="mini" type="text" icon="el-icon-search" v-if="scope.row.roomStatus == 1"
            @click="handleRecord(scope.row)">查看预约记录</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改一站式社区-功能房对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="60%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <div style="display: flex;">
          <div style="flex: 1;margin-right: 20px;">
            <el-form-item label="功能房名" prop="roomName">
              <el-input v-model="form.roomName" placeholder="请输入功能房名" />
            </el-form-item>
          </div>
          <div style="flex: 1;">
            <el-form-item label="容纳人数" prop="roomCapacity">
              <!-- <el-input v-model="form.roomCapacity" placeholder="请输入功能房可承载人数" /> -->
              <el-input-number v-model="form.roomCapacity" :min="1" :max="200" label="请输入容纳人数"
                style="width: 100%;"></el-input-number>
            </el-form-item>
          </div>
        </div>
        <el-form-item label="开放状态" prop="roomStatus">
          <el-radio-group v-model="form.roomStatus">
            <el-radio v-for="dict in dict.type.rt_fu_room_status" :key="dict.value" :label="dict.value">{{ dict.label
              }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="图片上传" prop="roomImgs">
          <image-upload v-model="form.roomImgs" />
        </el-form-item>
        <el-form-item label="设置预约规则">
          <!-- <el-table :data="tableData" border style="width: 100%">
            <el-table-column prop="setTime" label="设置时间" align="center">
            </el-table-column>
            <el-table-column v-for="item in tableData.weekday" :label="item.day" align="center">
            </el-table-column>
          </el-table> -->
          <div class="timetable">
            <table>
              <thead>
                <tr>
                  <th style="text-align: center;">星期</th>
                  <th style="text-align: center;">时间</th>
                </tr>
              </thead>
              <tbody>
                <tr v-for="(time, index) in times" :key="index">
                  <td style="width: 80px; text-align: center; background-color: #1890ff; color: white;">{{
                    weekdays[index]
                  }}</td>
                  <td>
                    <div style="display: flex; flex-wrap: wrap; align-items: center;">
                      <div v-for="(item, i) in time" :key="i" :class="`${item.isDel !== 0 ? '' : 'timeBox'}`"
                        @mouseenter="item.isHovered = true" @mouseleave="item.isHovered = false">
                        <div v-if="item.isDel === 0">
                          <el-tooltip class="item" effect="dark" content="删除时间段" placement="top-start"
                            v-if="item.isHovered">
                            <i class="el-icon-delete" style="cursor: pointer;" @click="delTime(index, i)"></i>
                          </el-tooltip>
                          <div style="display: flex;align-items: center;">
                            <div>
                              <input type="time" :value="item.value"
                                @input="updateTime(index, $event.target.value, '开始', i)" id="startTime"
                                placeholder="请选择开始时间" /> -
                              <input type="time" :value="item.valueEnd"
                                @input="updateTime(index, $event.target.value, '结束', i)" id="endTime"
                                placeholder="请选择结束时间" />
                            </div>
                            <div v-if="i !== time.length - 1" style="font-size: 30px;margin-left: 10px;">,</div>
                          </div>
                        </div>
                      </div>
                      <div style="margin-left: 20px;">
                        <el-tooltip class="item" effect="dark" content="增加时间段" placement="top-start">
                          <i class="el-icon-plus" style="cursor: pointer;" @click="addTime(index)"></i>
                        </el-tooltip>
                      </div>
                    </div>
                  </td>
                </tr>
              </tbody>
            </table>
          </div>
        </el-form-item>
        <el-form-item label="使用事项" prop="roomMatter">
          <el-input v-model="form.roomMatter" type="textarea" rows="5" placeholder="请输入使用事项" />
        </el-form-item>
        <!-- <el-form-item label="功能房预约规则" prop="roomRule">
          <el-input v-model="form.roomRule" placeholder="请输入功能房预约规则" />
        </el-form-item> -->
        <!-- <el-form-item label="功能房介绍" prop="roomInfo">
          <el-input v-model="form.roomInfo" placeholder="请输入功能房介绍" />
        </el-form-item>
        <el-form-item label="功能房用途" prop="roomPurp">
          <el-input v-model="form.roomPurp" placeholder="请输入功能房用途" />
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 查看使用情况 -->
    <el-dialog title="当前功能房使用情况" :visible.sync="openUsageSituation" width="60%" append-to-body>
      <div v-if="groupedByWeekday.length != 0">
        <div v-for="(item, i) in groupedByWeekday" :key="i">
          <el-row :gutter="10" style="padding: 10px;font-weight: bold;">
            <el-col :span="2">日期</el-col>
            <el-col :span="22">{{ item.ohWeekday }}</el-col>
          </el-row>
          <div style="display: flex;flex-wrap: wrap;">
            <el-card v-for="(hours, index) in item.data" :key="index" style="margin: 20px 10px;min-width: 250px;"
              :class="useHours(hours).rtCreatRole === '空闲' ? '' : 'cardBox'">
              <template>
                <div>
                  <el-row :gutter="10">
                    <el-col :span="6">时间段</el-col>
                    <el-col :span="18">{{ useHours(hours).rtTime }} {{ hours.openingHours }}</el-col>
                  </el-row>
                  <el-row :gutter="10" style="margin-top: 20px;">
                    <el-col :span="6">使用人</el-col>
                    <el-col :span="18">{{ useHours(hours).rtCreatRole }}</el-col>
                  </el-row>
                </div>
              </template>
            </el-card>
          </div>
        </div>
      </div>
      <div v-else style="text-align: center;">
        暂无功能房使用情况
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">关 闭</el-button>
      </div>
      <!-- <el-table v-loading="loading" :data="usageSituationList.staffOneStopRoomReservationList" v-if="usageSituationList.staffOneStopRoomReservationList.length != 0">
        <el-table-column label="申请人" align="center" prop="rtCreatRole" />
        <el-table-column label="功能房名" align="center" prop="roomName" />
        <el-table-column label="借用部门、学院" align="center" prop="rtDepar" />
        <el-table-column label="功能房名" align="center" prop="roomName" />
        <el-table-column label="预约时间段" align="center" prop="rtTimePeriod" />
        <el-table-column label="使用期间图片" align="center" prop="rtImgs" width="100">
          <template slot-scope="scope">
            <image-preview :src="scope.row.rtImgs" :width="50" :height="50" />
          </template>
        </el-table-column>
        <el-table-column label="使用状态" align="center" prop="rtState">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.rtState === 0">未使用</el-tag>
            <el-tag type="success" v-else-if="scope.row.rtState === 1">使用中</el-tag>
            <el-tag type="danger" v-else>使用结束</el-tag>
          </template>
        </el-table-column>
      </el-table>
      <div v-else style="text-align: center;">
        该功能房暂无使用情况
      </div> -->
    </el-dialog>
  </div>
</template>

<script>
import { listRoom, getRoom, delRoom, addRoom, updateRoom } from "@/api/staff/room";
import { addBatchRoomOpeningHours } from "@/api/staff/roomOpeningHours";

export default {
  name: "Room",
  dicts: ['rt_fu_room_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 一站式社区-功能房表格数据
      roomList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      openUsageSituation: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        roomNo: null,
        roomName: null,
        roomMatter: null,
        roomRule: null,
        roomInfo: null,
        roomPurp: null,
        roomStatus: null,
        roomCapacity: null,
        roomCreatetime: null,
        roomUptime: null,
        roomUpuser: null,
        roomUser: null,
        roomDepar: null,
        roomImgs: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        roomName: [
          { required: true, message: "功能房名不能为空", trigger: "blur" }
        ],
        roomStatus: [
          { required: true, message: "开放状态不能为空", trigger: "change" }
        ],
        roomCapacity: [
          { required: true, message: "功能房容纳人数", trigger: "blur" }
        ],
        roomMatter: [
        { required: true, message: "使用事项不能为空", trigger: "blur" }
        ]
      },
      weekdays: [
        '星期一',
        '星期二',
        '星期三',
        '星期四',
        '星期五',
        '星期六',
        '星期日'
      ],
      times: [
        [{ value: '08:00', valueEnd: '09:00', isHovered: false }, { value: '08:00', valueEnd: '12:00', isHovered: false }], // 星期一
        [], // 星期二
        [{ value: '09:00', valueEnd: '10:00', isHovered: false }], // 星期三
        [], // 星期四
        [{ value: '09:00', valueEnd: '10:30', isHovered: false }], // 星期五
        [{ value: '10:00', valueEnd: '12:00', isHovered: false }], // 星期六
        []      // 星期日（根据图片，星期日没有预设时间）
      ],
      // 使用情况
      usageSituationList: {
        staffOneStopRoomReservationList: []
      },
      // 功能房预约时间分组
      groupedByWeekday: []
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询一站式社区-功能房列表 */
    getList() {
      this.loading = true;
      listRoom(this.queryParams).then(response => {
        this.roomList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.openUsageSituation = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        roomId: null,
        roomNo: null,
        roomName: null,
        roomMatter: null,
        roomRule: null,
        roomInfo: null,
        roomPurp: null,
        roomStatus: null,
        roomCapacity: null,
        roomCreatetime: null,
        roomUptime: null,
        roomUpuser: null,
        roomUser: null,
        roomDepar: null,
        roomImgs: null
      };
      // 遍历times数组，并清空每个子数组
      this.times.forEach(day => {
        day.length = 0; // 清空子数组
      })
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.roomId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    // 打开查看使用情况对话框
    usageSituation(row) {
      this.openUsageSituation = true
      let data = JSON.stringify(row)
      this.usageSituationList = JSON.parse(data)

      // 筛选出预约功能房的时间段 正在使用的功能房预约记录
      this.usageSituationList.staffOneStopRoomReservationList = this.usageSituationList.staffOneStopRoomReservationList.filter(item => item.rtState !== 2)

      let reservationList = []
      // 根据预约记录，筛选出预约的时间段
      this.usageSituationList.staffOneStopRoomReservationList.forEach(element => {
        this.usageSituationList.staffOneStopRoomOpeningHoursList.forEach(el => {
          if (element.rtNo == el.rtNo) {
            reservationList.push(el)
          }
        });
      });

      // 对功能房的预约时间按日期分组
      // 使用 reduce 方法来按 "ohWeekday" 分组
      this.groupedByWeekday = reservationList.reduce((acc, curr) => {
        // 检查累加器中是否已经存在该 weekday
        const weekdayIndex = acc.findIndex(group => group.ohWeekday === curr.ohWeekday);

        if (weekdayIndex === -1) {
          // 如果不存在，则添加一个新的分组
          acc.push({
            ohWeekday: curr.ohWeekday,
            data: [curr] // 将当前对象放入新的 data 数组中
          });
        } else {
          // 如果存在，则将当前对象添加到对应的 data 数组中
          acc[weekdayIndex].data.push(curr);
        }

        return acc;
      }, []); // 注意初始累加器是一个空数组
    },
    // 筛选预约时间段是否使用,如果在使用则返回使用人名称，没有则显示空闲
    useHours(hours) {
      // 检查hours对象中是否存在isOccupy属性且其值为1 （0未使用 1使用）
      // if (hours && hours.isOccupy === 1) {
      // 如果isOccupy为1，执行相关逻辑
      const foundElement = this.usageSituationList.staffOneStopRoomReservationList.find(element => {
        return element.rtNo === hours.rtNo; // 使用严格等于进行比较
      });
      return foundElement ? { rtCreatRole: foundElement.rtCreatRole, rtTime: foundElement.rtTime } : { rtCreatRole: '空闲', rtTime: '暂无' }; // 如果找到元素，返回rtCreatRole（使用人），否则返回'空闲'
      // } else {
      // 如果isOccupy不为1，或者hours对象不存在，返回'空闲'
      // return '空闲';
      // }
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加一站式社区-功能房";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const roomId = row.roomId || this.ids
      getRoom(roomId).then(response => {
        this.form = response.data;
        if (this.form.staffOneStopRoomOpeningHoursList.length != 0) {
          this.times = this.revertDataToOriginalFormat(this.form.staffOneStopRoomOpeningHoursList)
        }
        this.open = true;
        this.title = "修改一站式社区-功能房";
      });
    },
    // 将页面上选择的时间段 压平数组，转成一个时间段一条数据，传到后端
    revertDataFormat(roomNoData) {
      // 使用flatMap按星期几提取时间段到数组，并修改属性名和添加新属性
      const organizedTimes = this.weekdays.flatMap((day, index) => {
        const ohWeekday = day; // 更改day为ohWeekday
        return this.times[index].map((time, idx) => {
          // 合并value和valueEnd到openingHours
          const openingHours = `${time.value}-${time.valueEnd}`;
          // 分配roomNo（这里简单使用递增计数器，实际情况可能不同）
          const roomNo = time.roomNo != null ? time.roomNo : roomNoData
          // 返回新对象
          return { ohWeekday, openingHours, isHovered: time.isHovered, roomNo, ohId: time.ohId, isDel: time.isDel };
        });
      }).filter(item => item); // 过滤掉空数组（虽然在这个例子中其实不需要，因为times数组中没有完全空的元素）

      return organizedTimes
    },
    // 将数据来源的时间段数组转化成页面显示的时间段
    revertDataToOriginalFormat(modifiedData) {
      // 创建一个空对象来按星期几存储时间段
      const originalFormat = {};

      // 遍历修改后的数据
      modifiedData.forEach(item => {
        // 确保originalFormat中有对应星期几的数组
        if (!originalFormat[item.ohWeekday]) {
          originalFormat[item.ohWeekday] = [];
        }

        // 将openingHours拆分为value和valueEnd，并添加到对应星期几的数组中
        const [value, valueEnd] = item.openingHours.split('-');
        const time = { value, valueEnd, isHovered: item.isHovered, roomNo: item.roomNo, ohId: item.ohId, isDel: 0 };
        originalFormat[item.ohWeekday].push(time);
      });

      // 将对象转换为按星期几排序的数组（如果需要的话）
      // 注意：由于weekdays数组已经定义了顺序，我们可以直接使用它
      // const weekdays = ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期日'];
      const sortedData = this.weekdays.map(day => originalFormat[day] || []); // 如果某天没有数据，则返回空数组

      return sortedData;
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          // 检查表单中是否有空字符串
          let hasEmptyString = Object.values(this.form).some(value => {
            return (value !== null && value !== undefined && (typeof value === 'string' ? value.trim() === '' : false));
          });

          if (hasEmptyString) {
            this.$modal.msgError("表单中存在空字符串，请填写完整");
            return;
          }
          if (this.form.roomId != null) {
            // console.log(this.times);
            // console.log(this.revertDataFormat(this.form.roomNo));
            this.form.staffOneStopRoomOpeningHoursList = this.revertDataFormat(this.form.roomNo)
            updateRoom(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRoom(this.form).then(response => {
              // console.log(response);
              if (response.code === 200) {
                // 处理选择的预约时间段规则
                let data = this.revertDataFormat(response.data.roomNo)
                // 处理好之后，批量添加到数据（每个时间段一条数据）
                addBatchRoomOpeningHours(data).then(response => {
                  this.$modal.msgSuccess("新增成功");
                  this.open = false;
                  this.getList();
                })
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const roomIds = row.roomId || this.ids;
      let that = this
      that.$modal.confirm('是否确认删除一站式社区-功能房编号为"' + roomIds + '"的数据项？').then(function () {
        delRoom(roomIds).then(response => {
          if (response.code !== 500) {
            that.$modal.msgSuccess("删除成功");
            that.getList();
          }
        });
      }).then(() => {
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('staff/room/export', {
        ...this.queryParams
      }, `room_${new Date().getTime()}.xlsx`)
    },
    // 预约规则设置时间
    updateTime(index, time, text, i) {
      if (text === '开始') {
        this.times[index][i].value = time;
      } else {
        if (!isTimeGreaterThanValue(time, this.times[index][i].value)) {
          this.$modal.msgError("结束时间不能小于开始时间");
          this.times[index][i].valueEnd = ''
          return
        }
        this.times[index][i].valueEnd = time;
      }

      function isTimeGreaterThanValue(time, value) {
        // 解析时间字符串，转换为分钟数
        function parseTimeToMinutes(timeStr) {
          const [hours, minutes] = timeStr.split(':').map(Number);
          return hours * 60 + minutes;
        }

        // 获取两个时间的分钟数
        const timeMinutes = parseTimeToMinutes(time);
        const valueMinutes = parseTimeToMinutes(value);

        // 比较时间
        return timeMinutes > valueMinutes;
      }
    },
    // 删除设置的时间
    delTime(index, i) {
      this.times[index][i].isDel = 1
      // this.times[index].splice(i, 1)
    },
    // 增加设置时间
    addTime(index) {
      this.times[index].push({
        value: '', valueEnd: '', isHovered: false, isDel: 0
      })
    },
    // 开放状态改变执行
    changeRoomStatus(row) {
      row.roomStatus = parseInt(row.roomStatus, 10);
      updateRoom(row).then(response => {
        this.$modal.msgSuccess("修改成功");
        this.getList();
      });
    },
    handleRecord(row) {
      this.$router.push({
        path: '/staff/oneStop/room/roomReservation',
        query: {
          roomNo: row.roomNo || null,
        },
      })
    }
  }
};
</script>

<style lang="scss" scoped>
.timetable table {
  width: 100%;
  border-collapse: collapse;
}

.timetable th,
.timetable td {
  border: 1px solid #ddd;
  padding: 8px;
  text-align: left;
}

.timetable th {
  background-color: #f2f2f2;
}

input[type="time"] {
  width: 70px;
  border: 0;
  /* Adjust the width as needed */
}

.timeBox {
  position: relative;
  max-width: 200px;
  padding: 10px;
}

.timeBox i {
  position: absolute;
  right: 0;
  top: 0;
}

::v-deep .main-el-switch {
  position: relative;

  .el-switch__core {
    height: 24px;
    border-radius: 12px;
    min-width: 65px;

    &:after {
      left: 4px;
      top: 3px;
    }
  }

  &.el-switch {
    &.is-checked {
      .el-switch__core {
        &:after {
          margin-left: -20px;
          left: 100%;
        }
      }
    }
  }

  &.is-checked {
    .el-switch__label--left {
      opacity: 0;
    }

    .el-switch__label--right {
      opacity: 1;
    }
  }

  .el-switch__label {
    position: absolute;
    top: 0;
  }

  .el-switch__label--left {
    right: 0;
    color: #999;
    z-index: 1;
    margin-right: 8px;
  }

  .el-switch__label--right {
    left: 0;
    color: #fff;
    opacity: 0;
    margin-left: 8px;
  }
}

#startTime,
#endTime {
  position: relative;
}

#startTime::-webkit-calendar-picker-indicator,
#endTime::-webkit-calendar-picker-indicator {
  position: absolute;
  right: 0;
  padding-left: calc(100% - 20px); // 我估计它本身也就40px吧，通过设置左内边距铺满输入框
  padding-right: 5px; // 为了美观，右侧给它来点空隙
}

.ellipsis {
  overflow: hidden;
  /* 确保超出容器的文本被隐藏 */
  white-space: nowrap;
  /* 防止文本换行 */
  text-overflow: ellipsis;
  /* 超出部分显示省略号 */
}

.cardBox {
  background-color: #1890ff;
  color: white;
}
</style>
